/**
 * 
 */
package org.andes.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.andes.kownledge.operator.Variable;
import org.armedbear.lisp.LispObject;
import org.armedbear.lisp.Symbol;

public class Bindings{
	public static Bindings no_bindings;
	static {
		no_bindings=new Bindings();
	}
		HashMap<Variable,Object> bindings=new HashMap<Variable,Object>();
	
		List<Binding> bindingList=new ArrayList<Binding>();
		public int getCount(){
			return bindingList.size();
		}
//		(defun get-binding (var bindings)
//		  "Find a (variable . value) pair in a binding list."
//		  (assoc var bindings))
		public Object get_binding(Variable var){
			return bindings.get(var);
		}
		public void addBinding(Binding binding){
			bindings.put(binding.getVar(), binding.getVal());
			bindingList.add(binding);
		}
		
		
		
		
//		(defun lookup (var bindings)
//		  "Get the value part (for var) from a binding list."
//		  (binding-val (get-binding var bindings)))
		public Object lookup(Variable var){
			return bindings.get(var);
			
		}
		
//		(defun extend-bindings (var val bindings)
//		  "Add a (var . value) pair to a binding list."
//		  (cons (make-binding var val)
//		        // Once we add a "real" binding,
//		        // we can get rid of the dummy no-bindings
//		        (if (eq bindings no-bindings)
//		            nil
//		            bindings)))
		public Bindings extend_bindings(Variable var,Object val){
			
			Binding binding=new Binding();
			binding.setVar(var);
			binding.setVal(val);
			Bindings result=new Bindings();
			result.addBinding(new Binding(var,val));
			result.addAllBindings(this.getAllBindings());
			return result;			
		}
public  void addAllBindings(List<Binding> allBindings) {
	this.bindingList.addAll(allBindings);
	for(Binding bd:bindingList)
	{
		bindings.put(bd.getVar(), bd.getVal());
	}
	
}
public List<Binding> getAllBindings() {
	
	 return bindingList;
}				
	}